Skip to content

fix(common-utils): apply Map KV items rewrite to SQL filters in $__filters - #3828

Draft
karl-power wants to merge 1 commit into
mainfrom
claude/raw-sql-filters-kv-rewrite
Draft

karl-power wants to merge 1 commit into
mainfrom
claude/raw-sql-filters-kv-rewrite

Conversation

@karl-power

Copy link
Copy Markdown
Contributor

Summary

SQL filters expanded by $__filters now use the KV items text index on Map keys, as Lucene filters in $__filters and SQL filters on builder tiles already do. Stacked on #3826.

  • renderFiltersToSql builds the KV items lookup and passes type: 'sql' filters through rewriteSqlFilterWithKvItems, like renderWhere does for builder tiles. This covers raw SQL tiles and SQL query dashboard filters (renderSourceFiltersToSql).
  • Ad hoc and dropdown dashboard filters on a raw SQL tile now render has(LogAttributeItems, ...) instead of toString(LogAttributes['k']) = 'v'.
  • Sources without a table (metric sources) are unchanged, and the lookup is only built when there is a SQL filter to rewrite.
  • $__filters must be placed where the source table's columns are visible, since the rewrite references the items ALIAS column. A SELECT * subquery does not expose ALIAS columns, so ... FROM (SELECT * FROM logs) WHERE $__filters now fails with an unknown identifier. Lucene filters in $__filters already have this constraint for exact Map matches, and the builder-to-SQL conversion places $__filters on the source table.

How to reproduce

Starting point: yarn dev, registered and logged in, on this branch's base (#3826) for "before".

Before:

  1. Create a dashboard with a raw SQL Number tile on the Logs source: SELECT count() FROM $__sourceTable WHERE $__timeFilter(Timestamp) AND $__filters.
  2. Click the filter icon ("Edit filters and variables") → "Add new filter", choose "Ad hoc keys and values", select Logs under "Data sources", and save.
  3. In the filter bar, click "+" next to the filter and add LogAttributes['teamName'], =, and your team name.
  4. Edit the tile, run the query, and open "Generated SQL" ("Apply filters" on). The expanded $__filters contains toString(LogAttributes['teamName']) = '<team>'.

On this branch:

  1. Repeat the steps. The expanded $__filters contains has(`LogAttributeItems`, concat('teamName', '=', '<team>')), and the tile count is unchanged.

References

@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 25, 2026 11:19am UTC
hyperdx-storybook Ready Ready Preview Nov 25, 2026 11:19am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f66a72

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Patch
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@karl-power
karl-power added this pull request to stack #3829 November 25, 2026 10:47
@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.12%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 478 passed • 1 skipped • 1062s

Status Count
✅ Passed 478
❌ Failed 0
⚠️ Flaky 10
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

Base automatically changed from claude/adhoc-filter-kv-rewrite to main November 25, 2026 11:15
…lters

Raw SQL tiles and SQL query dashboard filters expand $__filters through
renderFiltersToSql, which never built the KV items lookup, so SQL filters
on Map keys kept the Map subscript while Lucene filters got has().

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 7f66a72b Deployed Nov 25, 2026 by vercel[bot]
Preview – hyperdx-storybook — 7f66a72b Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant